$(function () {
    layui.use(['table','layer'],function () {
        var table = layui.table;
        var layer = layui.layer;
        table.render({
            elem:'#listSplit',
            url:'/pages/back/orderDe/listSplit',
            page:true,
            limit:10,
            cols:[[
                {field: 'orid', title: '订单编号',sort: true, fixed: 'left'},
                {field: 'cuid', title: '客户编号',sort: true, fixed: 'left'},
                {field: 'title', title: '货物名称',sort: true, fixed: 'left'},
                {field: 'number', title: '货物数量',sort: true, fixed: 'left'},
                {field: 'line', title: '目的地',sort: true, fixed: 'left'},
                {
                    field: 'orderdate',
                    title: '创建日期',
                    templet: "<div>{{layui.util.toDateString(d.orderdate,'yyyy-MM-dd HH:mm:ss')}}</div>"
                },
                {field:'status',title:'状态',templet:'#status'},
                {field:'right',title:'操作',templet:"#barOption"}
            ]]
        })
        table.on('tool(listSplit)',function (obj) {
            var data = obj.data;
            if(obj.event == "edit"){
                var orid = data.orid;
                var number =data.number;
               layer.open({
                   type:1,
                   title:'处理订单',
                   shade:0,
                   skin:'demo-class',
                   area: ['500px', '300px'],
                   content:
                   '<div class="layui-col-md10">' +
                   '<form class="layui-form" style="padding-top: 20px">'+
                   '<div class="layui-form-item">'+
                   '<label class="layui-form-label">当前数量</label>'+
                   ' <div class="layui-input-block">' +
                   '<input type="text" value='+number+' autocomplete="off" class="layui-input" disabled>'+
                   '</div>'+
                   '</div>'+
                   '<div class="layui-form-item">'+
                       '<label class="layui-form-label">价格/元</label>'+
                       ' <div class="layui-input-block">' +
                       '<input type="text" name="price" required  lay-verify="required|number" placeholder="请输入价格" autocomplete="off" class="layui-input">'+
                   '</div>'+
                       '</div>'+
                   '<div class="layui-form-item">' +
                   '<label class="layui-form-label">线路</label>' +
                   '<div class="layui-input-block">' +
                   '<select id="lid" name="lid">' +
                   '' +
                   '</select> ' +
                   '</div>' +
                   '</div>'+
                   '<div class="layui-form-item">' +
                   '<div class="layui-input-block">' +
                   '<input type="hidden" name="orid" value='+orid+'>' +
                   '<input type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-col-md-offset6"\n' +
                   '                                   lay-submit lay-filter="formDemo" id="editBtn" value="确认订单">\n' +
                   '                            <button type="reset" class="layui-btn layui-btn-danger layui-btn-sm">重置</button>' +
                   '</div>' +
                   '</div>' +
                   '</form>' +
                   '</div><div class="layui-col-md2">&nbsp;</div>'
               })
                $(function () {
                    layui.use(['form'],function () {
                        var form = layui.form;
                        $.post("/pages/back/line/list",{},function (obj) {
                            for(var i = 0;i<obj.length;i++){
                                $("#lid").append("<option value=" + obj[i].lid + ">" + obj[i].start + "<===>" + obj[i].end + "</option>")
                            }
                            form.render()
                        },'json')


                    })
                })
                $(function () {
                    $('#editBtn').on('click',function () {
                        $.ajax({
                            url:'/pages/back/orderDe/editOrderDe',
                            type:'post',
                            data:$('.layui-form').serialize(),
                            success:function (data) {
                                if(data=="success"){
                                    layer.msg("订单确认成功",{time:1000,icon:1,end:function () {
                                            window.location.href="/pages/back/orderDe/listSplitPre"
                                        }})
                                }else if (data=="isEmpty"){
                                    layer.msg("数据有误",{time:1000,icon:2})
                                }else{
                                    layer.msg("订单确认失败",{time:1000,icon:2})
                                }
                            }
                        })
                    })
                })
            }

        })

    })
})